/*
 * @Description: 
 * @Author: liks
 * @Date: 2025-01-06 11:07:12
 * @LastEditors: liks
 * @LastEditTime: 2025-01-23 16:13:53
 */
import {
  Body,
  Controller,
  Get,
  HttpCode,
  HttpStatus,
  Post,
  Request,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { LoginDto } from './dto/login.dto';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { Public } from './decorators/public.decorator';
import { CreateUserDto } from '../user/dto/create-user.dto';

@ApiTags('登录认证')
@Controller('auth')
export class AuthController {
  constructor(private authService: AuthService) {}

  @ApiOperation({ summary: '用户注册' })
  @Public()
  @Post('register')
  register(@Body() createUserDto: CreateUserDto) {
    console.log('用户注册', createUserDto);

    return this.authService.register(createUserDto);
  }

  @ApiOperation({ summary: '登录' })
  @Public()
  @HttpCode(HttpStatus.OK)
  @Post('login')
  login(@Body() loginDto: LoginDto) {
    return this.authService.login(loginDto);
  }

  @ApiOperation({ summary: '获取登录的用户信息' })
  @Get('userInfo')
  getUserInfo(@Request() req: any) {
    const user = req?.user;
    // console.log('获取登录的用户信息', user);
    return this.authService.getUserInfo(user?.uid);
  }
}
